home *** CD-ROM | disk | FTP | other *** search
- (*************************)
- (* Michael Coyle and Neal Tibrewala *)
- (* *)
- (* If you find this code useful, please *)
- (* send a postcard to: *)
- (* Neal Tibrewala *)
- (* P.O. Box 428 *)
- (* Old Westbury, N.Y. 11568 *)
- (*************************)
-
- program changeling (input, output);
-
- (* Changeling allows a user to change the creator and file types of any file. *)
- (* The file selection routine allows for both a dialog box and drag and drop. *)
-
- type
- pointer = ^nodetype;
- nodetype = record
- info: str255;
- aux: integer;
- link: pointer;
- end;
-
- var
- display, who, what: str255;
- deinfo: finfo;
- status: oserr;
- defile: pointer;
-
- procedure selector;
- (* Gets files to change by either dialog box or drag 'n drop, puts them on a linked list. *)
- var
- message, count: integer;
- procedure dragndrop;
- (* Handles drag 'n drop files with 'getappfiles'. *)
- var
- cryo: pointer;
- thefile: appfile;
- swiper: integer;
- begin
- new(defile);
- getappfiles(1, thefile); (* Gets the first dragged 'n dropped file. *)
- defile^.info := thefile.fname; (* Puts the file's name onto the linked list. *)
- defile^.aux := thefile.vrefnum; (* Puts on the Volume Reference Number. *)
- defile^.link := nil;
- cryo := defile;
- if count > 1 then
- for swiper := 2 to count do
- begin
- new(cryo^.link);
- cryo := cryo^.link;
- getappfiles(swiper, thefile); (* Gets the next few files, up to count. *)
- cryo^.info := thefile.fname; (* Puts the file's name onto the linked list. *)
- cryo^.aux := thefile.vrefnum; (* Puts on the Volume Reference Number. *)
- cryo^.link := nil;
- end;
- end;
- procedure dialogselect;
- (* Uses 'sfgetfile' to put up an 'open' dialog box to choose the file. *)
- var
- dlgorigin: point;
- zetypelist: sftypelist;
- rsvp: sfreply;
- begin
- new(defile);
- defile^.link := nil;
- setpt(dlgorigin, 80, 60); (* Sets the dialog box location to 80, 60*)
- sfgetfile(dlgorigin, '', nil, -1, zetypelist, nil, rsvp); (* Puts up an 'open' dialog box. *)
- if not rsvp.good then (* If the cancel button was pressed, good is false. *)
- halt;
- defile^.info := rsvp.fname; (* Puts the file's name onto the linked list. *)
- defile^.aux := rsvp.vrefnum; (* Puts on the Volume Reference Number. *)
- end;
-
- (* Main procedure calls 'countappfiles' to see if files were dragged. *)
- begin
- countappfiles(message, count); (* Counts number of dragged 'n dropped files. *)
- if count = 0 then
- dialogselect (* Calls up the 'open' dialog box and handles choice. *)
- else
- dragndrop; (* Handles dragged 'n dropped files. *)
- end;
-
- procedure changer;
- (* Takes files from the linked list and allows the user to change the types. *)
- var
- choice, itemtype, loop: integer;
- itemhandle: handle;
- itemrect: rect;
- dedialog: dialogptr;
- done: boolean;
- begin
- while defile <> nil do (* This will run until the linked list is out of files. *)
- begin
- done := false;
- display := defile^.info;
- status := getfinfo(defile^.info, defile^.aux, deinfo); (* Gets info about the current file. *)
- while pos(display, ':') <> 0 do
- delete(display, 1, pos(display, ':'));
- paramtext(display, '', '', ''); (* Puts the name of the current file into the next dialog. *)
- who := deinfo.fdcreator; (* Assigns the creator type to 'who'. *)
- what := deinfo.fdtype; (* Assigns the file type to 'what'. *)
- dedialog := getnewdialog(1001, nil, windowptr(-1)); (* Loads dialog 1001 into 'dedialog' from rsrc file. *)
- setport(dedialog); (* Makes 'dedialog' active. *)
- showwindow(dedialog); (* Shows 'dedialog'. *)
- getditem(dedialog, 4, itemtype, itemhandle, itemrect); (* Makes dialog item 4 ready to accept data. *)
- setitext(itemhandle, deinfo.fdcreator); (* Puts the creator type into item 4. *)
- getditem(dedialog, 6, itemtype, itemhandle, itemrect); (* Makes dialog item 6 ready to accept data. *)
- setitext(itemhandle, deinfo.fdtype); (* Puts the file type into item 6. *)
- while not done do (* Checks if user has pressed the 'OK' button. *)
- begin
- modaldialog(nil, choice); (* Finds out what item the user clicked on. *)
- case choice of (* Handles the user's choice. *)
- 1:
- done := true;
- 4, 6:
- begin
- getditem(dedialog, choice, itemtype, itemhandle, itemrect); (* Makes the selected item ready to accept data. *)
- if choice = 4 then
- getitext(itemhandle, who) (* Puts what the user typed into 'who'. *)
- else
- getitext(itemhandle, what); (* Puts what the user typed into 'what'. *)
- end;
- 7:
- halt;
- end;
- end;
- deinfo.fdcreator := copy(who, 1, 4); (* Assigns the user's creator type to the info record. *)
- deinfo.fdtype := copy(what, 1, 4); (* Assigns the user's file type to the info record. *)
- hidewindow(dedialog); (* Hides 'dedialog'. *)
- disposewindow(dedialog); (* Dumps 'dedialog' from memory. *)
- if status = noerr then (* If there is no operating system error, the new info is saved. *)
- status := setfinfo(defile^.info, defile^.aux, deinfo);
- defile := defile^.link;
- end;
- end;
-
- begin
- setcursor(arrow); (* Sets the mouse cursor to an arrow. *)
- selector; (* Selects the files to change. *)
- changer; (* Allows user to input changes into a dialog box. *)
- end.